﻿using OrderStateMachineWebApi.Models;
using OrderStateMachineWebApi.Services;

namespace OrderStateMachineWebApi.ServicesImpl
{

    public class PendingPaymentState : IOrderState
    {
        public OrderStatus Status => OrderStatus.PendingPayment;

        public async Task PayAsync(Order order)
        {
            // 执行支付逻辑
            await Task.Delay(100); // 模拟支付处理时间

            // 状态转换
            order.Status = OrderStatus.Paid;
            order.UpdatedAt = DateTime.UtcNow;
            order.Notes += $"[{DateTime.UtcNow:o}] 订单已支付; ";
        }

        public Task ProcessAsync(Order order)
        {
            throw new InvalidOperationException("待支付订单不能直接处理");
        }

        public Task ShipAsync(Order order)
        {
            throw new InvalidOperationException("待支付订单不能直接发货");
        }

        public Task CompleteAsync(Order order)
        {
            throw new InvalidOperationException("待支付订单不能直接完成");
        }

        public async Task CancelAsync(Order order)
        {
            // 执行取消逻辑
            await Task.Delay(50); // 模拟取消处理时间

            // 状态转换
            order.Status = OrderStatus.Cancelled;
            order.UpdatedAt = DateTime.UtcNow;
            order.Notes += $"[{DateTime.UtcNow:o}] 订单已取消; ";
        }

        public Task StartRefundAsync(Order order)
        {
            throw new InvalidOperationException("待支付订单不能退款");
        }

        public Task CompleteRefundAsync(Order order)
        {
            throw new InvalidOperationException("待支付订单不能完成退款");
        }
    }

}
